package snapex.expense.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import snapex.core.model.Result;
import snapex.core.model.SearchParams;
import snapex.expense.service.ISyncService;

@Slf4j
@RestController
public class SyncronizationController {
//	@Autowired
//	private HtcExpenseServiceFacade htcExpenseService;
		
	@Autowired
	private ISyncService syncService;
		
//	@ApiOperation(value="retrieve expense from e-expense")
//	@GetMapping(value = "/expense/list", produces=MediaType.APPLICATION_JSON_UTF8_VALUE)
//	public ResponseEntity<Result> listExpense(@RequestParam(required=false) String projectId) throws Exception {		
//		return ResponseEntity.ok(Result.success().data(htcExpenseService.getExpenses(projectId)));		
//	}
	
	@ApiOperation(value="sync expense to e-expense")
	@RequestMapping(value = "/expense/sync", method = {RequestMethod.GET, RequestMethod.POST}, produces=MediaType.APPLICATION_JSON_UTF8_VALUE)
	public ResponseEntity<Result> syncExpense(SearchParams params) throws Exception {
				
		return ResponseEntity.ok(syncService.syncExpenses(params));		
	}
	
	@ApiOperation(value="sync staff info from e-expense")
	@GetMapping(value = "/sync/staffinfo", produces=MediaType.APPLICATION_JSON_UTF8_VALUE)
	public ResponseEntity<Result> syncStaffData() throws Exception {			
		return ResponseEntity.ok(syncService.syncStaffInfo());	
	}
	
	@ApiOperation(value="sync project info from e-expense")
	@GetMapping(value = "/sync/projectinfo", produces=MediaType.APPLICATION_JSON_UTF8_VALUE)
	public ResponseEntity<Result> syncProjectCustomerInfo() throws Exception {				
		return ResponseEntity.ok(syncService.syncProjectCustomerInfo());	
	}
	
	@ApiOperation(value="sync current rate from e-expense")
	@GetMapping(value = "/sync/currencyrate", produces=MediaType.APPLICATION_JSON_UTF8_VALUE)
	public ResponseEntity<Result> syncCurrencyRate(@RequestParam(required=false) String rateMonth) throws Exception {	
		return ResponseEntity.ok(syncService.syncCurrencyRate(rateMonth));	
	}
	
	@ApiOperation(value="sync user groups from e-expense")
	@GetMapping(value = "/sync/usergroups", produces=MediaType.APPLICATION_JSON_UTF8_VALUE)
	public ResponseEntity<Result> syncUserGroups() throws Exception {		
		return ResponseEntity.ok(syncService.syncUserGroups());	
	}
	
	@ApiOperation(value="sync user authority  from e-expense")
	@GetMapping(value = "/sync/userauthority", produces=MediaType.APPLICATION_JSON_UTF8_VALUE)
	public ResponseEntity<Result> syncUserAuthority() throws Exception {		
		return ResponseEntity.ok(syncService.syncUserAuthority());	
	}
}
